package org.social.db.bean;

import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import org.apache.commons.lang3.ArrayUtils;
import org.social.db.cache.GiftCodeCache;
import com.sojoys.artifact.build.data.base.BasePojo;
import java.sql.SQLException;
import java.util.List;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.tools.SK_Plus;
import com.sojoys.artifact.tools.ToolCopy;
import java.sql.ResultSet;
import java.util.Map;
import org.social.db.cache.GiftPackageCache;
import com.alibaba.fastjson.JSONObject;
import static org.social.db.StaticResource.GiftCodeResource.*;
import com.sojoys.artifact.constant.DataModelKeyEnum;
import static org.social.db.StaticResource.GiftCodeResource.*;
/**
 * 礼包码
 */
public class GiftCode extends BasePojo<GiftCode> {
	
	
	/**
	 * 索引值
	 */
	private String[] indexValues = new String[3];
	
	/**
	* id
	*/
	private int id;
	
	/**
	* 礼包ID
	*/
	private int giftPackageId;
	
	/**
	* 礼包码名称
	*/
	private String name;
	
	/**
	* 礼包码
	*/
	private String code;
	
	/**
	* 限定次数
	*/
	private int limitCount;
	
	/**
	* 平台
	*/
	private String platform;
	
	/**
	* 渠道
	*/
	private int channelId;
	
	/**
	* 开始时间
	*/
	private java.util.Date startTime;
	
	/**
	* 结束时间
	*/
	private java.util.Date endTime;
	
	/**
	* 已领记录
	*/
	private Map gainLog;
	
	/**
	* 描述
	*/
	private String remark;
	
	/**
	* create_date
	*/
	private java.util.Date createDate;
	
	/**
	* modified_date
	*/
	private java.util.Date modifiedDate;
	
	
	@Deprecated
	public static GiftCode builder() {
		GiftCode giftCode = new GiftCode();
		return giftCode;
	}
	
	@Deprecated
	public GiftCode() {
		super();
	}
	
	public GiftCode(int id, int giftPackageId, String name, String code, int limitCount, String platform, int channelId, java.util.Date startTime, java.util.Date endTime, Map gainLog, String remark) {
		super();
		this.id = id;
		this.giftPackageId = giftPackageId;
		this.name = name;
		this.code = code;
		this.limitCount = limitCount;
		this.platform = platform;
		this.channelId = channelId;
		this.startTime = startTime;
		this.endTime = endTime;
		this.gainLog = gainLog;
		this.remark = remark;
		this.createDate = new java.util.Date();
		this.modifiedDate = new java.util.Date();
	}
	
	/**
	 * id
	 */
	public int getId() {return id;}
	
	/**
	 * id
	 */
	public GiftCode setId(int id) {this.id = id;return this;}
	
	/**
	 * 礼包ID
	 */
	public int getGiftPackageId() {return giftPackageId;}
	
	/**
	 * 礼包ID
	 */
	public GiftCode setGiftPackageId(int giftPackageId) {this.giftPackageId = giftPackageId;return this;}
	
	/**
	 * 礼包码名称
	 */
	public String getName() {return name;}
	
	/**
	 * 礼包码名称
	 */
	public GiftCode setName(String name) {this.name = name;return this;}
	
	/**
	 * 礼包码
	 */
	public String getCode() {return code;}
	
	/**
	 * 礼包码
	 */
	public GiftCode setCode(String code) {this.code = code;return this;}
	
	/**
	 * 限定次数
	 */
	public int getLimitCount() {return limitCount;}
	
	/**
	 * 限定次数
	 */
	public GiftCode setLimitCount(int limitCount) {this.limitCount = limitCount;return this;}
	
	/**
	 * 平台
	 */
	public String getPlatform() {return platform;}
	
	/**
	 * 平台
	 */
	public GiftCode setPlatform(String platform) {this.platform = platform;return this;}
	
	/**
	 * 渠道
	 */
	public int getChannelId() {return channelId;}
	
	/**
	 * 渠道
	 */
	public GiftCode setChannelId(int channelId) {this.channelId = channelId;return this;}
	
	/**
	 * 开始时间
	 */
	public java.util.Date getStartTime() {return startTime;}
	
	/**
	 * 开始时间
	 */
	public GiftCode setStartTime(java.util.Date startTime) {this.startTime = startTime;return this;}
	
	/**
	 * 结束时间
	 */
	public java.util.Date getEndTime() {return endTime;}
	
	/**
	 * 结束时间
	 */
	public GiftCode setEndTime(java.util.Date endTime) {this.endTime = endTime;return this;}
	
	/**
	 * 已领记录
	 */
	public Map getGainLog() {return gainLog;}
	
	/**
	 * 已领记录
	 */
	public GiftCode setGainLog(Map gainLog) {this.gainLog = gainLog;return this;}
	
	/**
	 * 已领记录
	 */
	public byte[] getGainLogByte() {
		return toBytes(gainLog);
	}
	
	/**
	 * 已领记录
	 */
	public Map initGainLogByte(byte[] _byte) {
		return (Map)forBytesObject(_byte);
	}	
	/**
	 * 描述
	 */
	public String getRemark() {return remark;}
	
	/**
	 * 描述
	 */
	public GiftCode setRemark(String remark) {this.remark = remark;return this;}
	
	/**
	 * create_date
	 */
	public java.util.Date getCreateDate() {return createDate;}
	
	/**
	 * create_date
	 */
	protected GiftCode setCreateDate(java.util.Date createDate) {this.createDate = createDate;return this;}
	
	/**
	 * modified_date
	 */
	public java.util.Date getModifiedDate() {return modifiedDate;}
	
	/**
	 * modified_date
	 */
	protected GiftCode setModifiedDate(java.util.Date modifiedDate) {this.modifiedDate = modifiedDate;return this;}
	
	
	// 代理
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected Object[] getFKTableNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_TABLE_NAMES;
		case PINGYING:
			return FK_PINGYING_TABLE_NAMES;
		case HASHCODE:
			return FK_HASHCODE_TABLE_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected Object[] getFKColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_COLUMN_NAMES;
		case PINGYING:
			return FK_PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return FK_HASHCODE_COLUMN_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected String[] getColumnTypes(){
		return COLUMN_COLUMNTYPES;
	}
	
	protected int getColumnCount(){
		return COLUMN_COUNT;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.giftPackageId;
        values[2] = this.name;
        values[3] = this.code;
        values[4] = this.limitCount;
        values[5] = this.platform;
        values[6] = this.channelId;
        values[7] = this.startTime;
        values[8] = this.endTime;
        values[9] = this.gainLog;
        values[10] = this.remark;
        values[11] = this.createDate;
        values[12] = this.modifiedDate;
        return values;
	}
	
	public GiftCode deepCopy(){
		GiftCode giftCode = null;
		try {
			giftCode = (GiftCode) super.clone();
		    giftCode.setStartTime(ToolCopy.copyObject(this.startTime));
		    giftCode.setEndTime(ToolCopy.copyObject(this.endTime));
		    giftCode.setGainLog(ToolCopy.copyObject(this.gainLog));
		    giftCode.setCreateDate(ToolCopy.copyObject(this.createDate));
		    giftCode.setModifiedDate(ToolCopy.copyObject(this.modifiedDate));
		    // 克隆索引
		    giftCode.indexValues = ArrayUtils.clone(indexValues);
			return giftCode;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return giftCode;
	}
	
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.id);
        map.put(keys[1], this.giftPackageId);
        map.put(keys[2], this.name);
        map.put(keys[3], this.code);
        map.put(keys[4], this.limitCount);
        map.put(keys[5], this.platform);
        map.put(keys[6], this.channelId);
        map.put(keys[7], this.startTime);
        map.put(keys[8], this.endTime);
        map.put(keys[9], this.gainLog);
        map.put(keys[10], this.remark);
        map.put(keys[11], this.createDate);
        map.put(keys[12], this.modifiedDate);
        return map;
    }
    
    protected GiftCode createForMap(Object[] keys,Map map){
   		this.id = (int)map.get(keys[0]);
   		this.giftPackageId = (int)map.get(keys[1]);
   		this.name = (String)map.get(keys[2]);
   		this.code = (String)map.get(keys[3]);
   		this.limitCount = (int)map.get(keys[4]);
   		this.platform = (String)map.get(keys[5]);
   		this.channelId = (int)map.get(keys[6]);
   		this.startTime = (java.util.Date)map.get(keys[7]);
   		this.endTime = (java.util.Date)map.get(keys[8]);
   		this.gainLog = (Map)map.get(keys[9]);
   		this.remark = (String)map.get(keys[10]);
   		this.createDate = (java.util.Date)map.get(keys[11]);
   		this.modifiedDate = (java.util.Date)map.get(keys[12]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.id);
        obj.put(keys[1], this.giftPackageId);
        obj.put(keys[2], this.name);
        obj.put(keys[3], this.code);
        obj.put(keys[4], this.limitCount);
        obj.put(keys[5], this.platform);
        obj.put(keys[6], this.channelId);
        obj.put(keys[7], this.startTime);
        obj.put(keys[8], this.endTime);
        obj.put(keys[9], toBytes(gainLog));
        obj.put(keys[10], this.remark);
        obj.put(keys[11], this.createDate);
        obj.put(keys[12], this.modifiedDate);
        return obj;
    }
    
    protected GiftCode createForJSONObject(Object[] keys,JSONObject obj){
	    this.id = obj.getIntValue(keys[0]);
	    this.giftPackageId = obj.getIntValue(keys[1]);
	    this.name = obj.getString(keys[2]);
	    this.code = obj.getString(keys[3]);
	    this.limitCount = obj.getIntValue(keys[4]);
	    this.platform = obj.getString(keys[5]);
	    this.channelId = obj.getIntValue(keys[6]);
	    this.startTime = obj.getDate(keys[7]);
	    this.endTime = obj.getDate(keys[8]);
		this.gainLog = (Map)forBytesObject(obj.getBytes(keys[9]));
	    this.remark = obj.getString(keys[10]);
	    this.createDate = obj.getDate(keys[11]);
	    this.modifiedDate = obj.getDate(keys[12]);
        return this;
    }
    
    
    public GiftCode createForResultSet(ResultSet rs) throws SQLException{
	    this.id = rs.getInt(SOURCE_COLUMN_NAMES[0]);
	    this.giftPackageId = rs.getInt(SOURCE_COLUMN_NAMES[1]);
	    this.name = rs.getString(SOURCE_COLUMN_NAMES[2]);
	    this.code = rs.getString(SOURCE_COLUMN_NAMES[3]);
	    this.limitCount = rs.getInt(SOURCE_COLUMN_NAMES[4]);
	    this.platform = rs.getString(SOURCE_COLUMN_NAMES[5]);
	    this.channelId = rs.getInt(SOURCE_COLUMN_NAMES[6]);
	    this.startTime = rs.getTimestamp(SOURCE_COLUMN_NAMES[7]);
	    this.endTime = rs.getTimestamp(SOURCE_COLUMN_NAMES[8]);
		this.gainLog = (Map)forBytesObject(rs.getBytes(SOURCE_COLUMN_NAMES[9]));
	    this.remark = rs.getString(SOURCE_COLUMN_NAMES[10]);
	    this.createDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[11]);
	    this.modifiedDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[12]);
	    return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeInt(this.id);
	    byteBuf.writeInt(this.giftPackageId);
	    byteBuf.writeString(this.name);
	    byteBuf.writeString(this.code);
	    byteBuf.writeInt(this.limitCount);
	    byteBuf.writeString(this.platform);
	    byteBuf.writeInt(this.channelId);
	    byteBuf.writeDate(this.startTime);
	    byteBuf.writeDate(this.endTime);
	    byteBuf.writeObject(this.gainLog);
	    byteBuf.writeString(this.remark);
	    byteBuf.writeDate(this.createDate);
	    byteBuf.writeDate(this.modifiedDate);
    }
	
	protected GiftCode readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readInt(null);
	    this.giftPackageId = byteBuf.readInt(null);
	    this.name = byteBuf.readString(null);
	    this.code = byteBuf.readString(null);
	    this.limitCount = byteBuf.readInt(null);
	    this.platform = byteBuf.readString(null);
	    this.channelId = byteBuf.readInt(null);
	    this.startTime = byteBuf.readDate(null);
	    this.endTime = byteBuf.readDate(null);
	    this.gainLog = (Map)byteBuf.readObject();
	    this.remark = byteBuf.readString(null);
	    this.createDate = byteBuf.readDate(null);
	    this.modifiedDate = byteBuf.readDate(null);
	    return this;
	}
    
    
    protected JSONObject exportFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
        return map;
    }
    
    protected boolean importFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
		return true;
    }
    
	/** 取得[gift_package]*/
	public GiftPackage getGiftPackagePkGiftPackageId(){
		return GiftPackageCache.me().getById(giftPackageId);
	}
	
    /** 级联删除(延迟入库) */
    public boolean deleteAndSon(){
    	return false;
    }
    
    /** 级联删除(及时入库) */
    public boolean deleteAndSonAndFlush(){
    	return false;
    }
    
    /** 延迟插入数据库 */
    public GiftCode insert(){
    	return GiftCodeCache.me().insert(this);
    }
    /** 延迟更新数据库 */
    public GiftCode update(){
    	return GiftCodeCache.me().update(this);
    }
    /** 延迟删除数据库 */
    public boolean delete(){
    	return GiftCodeCache.me().delete(this);
    }
    /** 即时插入数据库 */
    public GiftCode insertAndFlush(){
    	return GiftCodeCache.me().insertAndFlush(this);
    }
    /** 即时更新数据库 */
    public GiftCode updateAndFlush(){
    	return GiftCodeCache.me().updateAndFlush(this);
    }
    /** 即时删除数据库 */
    public boolean deleteAndFlush(){
    	return GiftCodeCache.me().deleteAndFlush(this);
    }
    
    
	
	/**
	 * 同步索引值
	 */
	public GiftCode syncIndexValues(){
		indexValues[0] = SK_Plus.b(getId()).e();
		indexValues[1] = SK_Plus.b(getCode()).e();
		indexValues[2] = SK_Plus.b(getGiftPackageId()).e();
		return this;
	}
	/**
	 * 取得索引
	 */
	public String[] getIndexValues(){
		return indexValues;
	}
	
	protected Object getPrimaryKey(){
		return getId();
	}
	
	protected void setPrimaryKey(Object key){
		setId((int)key);
	}
//自定义内容起始位置
//自定义内容结束位置
}